#include <stdio.h>
#include "status.h"
#include "batteries.h"

static const char *
batteries[] = {
    "/sys/bus/acpi/drivers/battery/PNP0C0A:00/power_supply/BAT0/capacity",
    NULL,
};

int
read_batteries(Arg * arg)
{
    int sum  = 0,
        temp = 0,
        i    = 0;
    FILE * file;

    for (; *(batteries + i); i++) {
        file = fopen(*(batteries + i), "r");
        fscanf(file, "%d", &temp);
        sum += temp;
        fclose(file);
    }

    return (int) (sum / i);
}
